local xingfeng = fk.CreateSkill {
  name = "lingling__xingfeng",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__xingfeng"] = "腥风",
  [":lingling__xingfeng"] = "锁定技，你每轮首个回合结束后，你弃置一张牌，进行一个额外回合，该回合你造成的伤害+1，"..
  "且回合结束时所有角色将体力调整至与回合开始时相同。",

  ["$lingling__xingfeng1"] = "驱逐胡虏，恢复中华！",
}

xingfeng:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(xingfeng.name) and
      player:usedSkillTimes(xingfeng.name, Player.HistoryRound) == 0
  end,
  on_use = function (self, event, target, player, data)
    player.room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = xingfeng.name,
      cancelable = false,
    })
    if not player.dead then
      player:gainAnExtraTurn(true, xingfeng.name)
    end
  end,

  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return not player.dead and data.reason == xingfeng.name
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    player.hp = math.min(player.maxHp, player:getMark("lingling__xingfeng-turn"))
    room:broadcastProperty(player, "hp")
  end,
})

xingfeng:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    if player.room.current == player then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      return turn_event and turn_event.data.who == player and turn_event.data.reason == xingfeng.name
    end
  end,
  on_use = function (self, event, target, player, data)
    data:changeDamage(1)
  end,
})

xingfeng:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.reason == xingfeng.name
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:setPlayerMark(p, "lingling__xingfeng-turn", p.hp)
    end
  end,
})

return xingfeng
